package org.linlinjava.litemall.web.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.service.LitemallSystemConfigService;
import org.linlinjava.litemall.web.annotation.LogAnno;
import org.linlinjava.litemall.web.annotation.LoginShop;
import org.linlinjava.litemall.web.annotation.LoginUser;
import org.linlinjava.litemall.web.dto.AdminSettlementRecordDTO;
import org.linlinjava.litemall.web.service.WebConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;

/**
 * 网络配置控制器
 *
 * @author yliyun
 * @description：系统配置读取
 * @date 2022/09/14
 */
@RestController
@RequestMapping("/web/config")
public class WebConfigController {
    /**
     * 系统配置服务
     */
    @Autowired
    private LitemallSystemConfigService systemConfigService;


    @Autowired
    private WebConfigService webConfigService;
    /**
     * 结算清单
     *
     * @param userId 用户id
     * @return {@link Object}
     */
    @GetMapping("settlement")
    @LogAnno
    public Object listSettlement(@LoginUser Integer userId){
        if(userId == null){
            return ResponseUtil.unlogin();
        }
        return ResponseUtil.ok(systemConfigService.listSettlementList());
    }


    /**
     * 强制下班API
     *
     * @param userId   用户id
     * @param username 用户名
     * @param password 密码
     * @return {@link Object}
     */
    @ApiOperation(value = "强制下班API")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username",value = "用户名"),
            @ApiImplicitParam(name = "password",value = "登录密码")
    })
    @PostMapping(value = "forcedToWork")
    public Object forcedToWork(@LoginUser Integer userId,
                               @LoginShop Integer shopId,
                               @RequestParam("username") @NotNull String username,
                               @RequestParam("password") @NotNull String password){
        if(userId == null){
            return ResponseUtil.unlogin();
        }
        return webConfigService.forcedToWork(username,password,shopId);
    }


    /**
     * 金额不一致结算记录
     *
     * POS下班结算与日中结算如果应收金额与实收金额不一致，则无法下班（需要能够记录然后还是能够登出）
     * @param userId 用户id
     * @return {@link ResponseUtil.Response}
     */
    @ApiOperation(value = "结算不一致记录")
    @PostMapping(value = "settlementRecord")
    public ResponseUtil.Response settlementRecord(@ApiIgnore @LoginUser Integer userId,
                                                  @ApiIgnore @LoginShop Integer shopId,
                                                  @RequestBody AdminSettlementRecordDTO settlementRecordDto
    ){
        return webConfigService.settlementRecord(userId,shopId,settlementRecordDto);
    }

}
